//n进制转化为10进制
#include<bits/stdc++.h>
using namespace std;

int CharToInt(char target){
    if(target>='0'&&target<='9'){
        return target-'0';
    }else{
        return target-'A'+10;
    }
}

void Convert(string str,int x){
    int number=0;
    for(int i=0;i<str.size();++i){
       number*=x;
       number+=CharToInt(str[i]);
    }
    printf("%d\n",number);
}

int main(){
    string str;
    while(cin>>str){
        str=str.substr(2);//如0x35
        Convert(str,n);
    }
    return 0;
}
